//
//  HEIMSickbedCell.m
//  HealthElderly
//
//  Created by 吴欧 on 2021/6/30.
//  Copyright © 2021 honglutec. All rights reserved.
//

#import "HEIMSickbedCell.h"
#import "HEDocImMsgModel.h"

@interface HEIMSickbedCell ()
 
@property (nonatomic, strong) UILabel *docTitleLb;
@property (nonatomic, strong) UILabel *nurseTitlLb;
@property (nonatomic, strong) UILabel *tagLb;
@property (nonatomic, strong) UILabel *contentLb;
@property (nonatomic, strong) UILabel *timeLb;
@property (nonatomic, strong) UILabel *descLb;

@end

@implementation HEIMSickbedCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.contentView.backgroundColor = CLightGrayColor;

        [self initUI];
    }
    return self;
}

- (void)initUI {
    
    UIView *warp = [UIView new];
    warp.backgroundColor = KWhiteColor;
    [self.contentView addSubview:warp];
 
    warp.layer.shadowColor = [UIColor colorWithRed:13/255.0 green:98/255.0 blue:218/255.0 alpha:0.08].CGColor;
    warp.layer.shadowOffset = CGSizeMake(0,5);
    warp.layer.shadowOpacity = 1;
    warp.layer.shadowRadius = 6;
    warp.layer.cornerRadius = 8;
 
    [warp mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).mas_offset(0);
        make.left.equalTo(self.contentView).mas_offset(15);
        make.right.equalTo(self.contentView).mas_offset(-15);
        make.bottom.equalTo(self.contentView).mas_offset(-15);
    }];
    
    
    // head
    UILabel *docTitleLb = [UILabel new];
    docTitleLb.text = @"主管医生：";
    docTitleLb.font = DYFont(16);
    docTitleLb.textColor = CNavLightBlackColor;
    [warp addSubview: docTitleLb];
    
    UILabel *nurseTitlLb = [UILabel new];
    nurseTitlLb.text = @"主管护士：";
    nurseTitlLb.font = DYFont(16);
    nurseTitlLb.textColor = CNavDargGrayColor;
    [warp addSubview: nurseTitlLb];
    
    _timeLb = [UILabel new];
    _timeLb.text = @"";
    _timeLb.font = DYFont(16);
    _timeLb.textColor = CNavDargGrayColor;
    [warp addSubview: _timeLb];
    
     
    _docTitleLb = [UILabel new];
    _docTitleLb.text = @"-";
    _docTitleLb.font = DYBlodFont(17);
    _docTitleLb.textColor = CNavLightBlackColor;
    [warp addSubview:_docTitleLb];
    
    _nurseTitlLb = [UILabel new];
    _nurseTitlLb.text = @"-";
    _nurseTitlLb.font = DYFont(16);
    _nurseTitlLb.textColor = CNavDargGrayColor;
    _nurseTitlLb.numberOfLines = 0;
    [warp addSubview:_nurseTitlLb];
    
    // 标签   我的医生 \ 关注
    _tagLb = [UILabel new];
    _tagLb.text = @"病床";
    _tagLb.backgroundColor = CPriceColor;
    _tagLb.textColor = KWhiteColor;
    _tagLb.font = DYBlodFont(14);
    _tagLb.textAlignment = NSTextAlignmentCenter;
    [warp addSubview:_tagLb];
    _tagLb.layer.cornerRadius = 3;
    _tagLb.layer.masksToBounds = YES;

    // 描述
    _descLb = [UILabel new];
    _descLb.text = @"";
    _descLb.font = DYFont(16);
    _descLb.textColor = CGrayColor;
    _descLb.numberOfLines = 2;
    _descLb.lineBreakMode = NSLineBreakByCharWrapping;
    [warp addSubview:_descLb];
    
    
    [_timeLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(warp).offset(15);
        make.left.equalTo(_docTitleLb.mas_right);
        make.right.equalTo(warp).offset(-15).priorityHigh();
    }];
    [_timeLb setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
 
    
    [docTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(warp).offset(15);
        make.left.equalTo(warp).offset(15);
        make.right.equalTo(_docTitleLb.mas_left);
    }];
    [docTitleLb setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
 
    [nurseTitlLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_docTitleLb.mas_bottom).offset(10);
        make.left.equalTo(warp).offset(15);
        make.right.equalTo(_nurseTitlLb.mas_left);
    }];
    [nurseTitlLb setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
    
    
    [_docTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(warp).offset(15);
        make.left.equalTo(docTitleLb.mas_right);
        make.right.equalTo(_timeLb.mas_left).offset(-10);
    }];
    
    [_nurseTitlLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_docTitleLb.mas_bottom).offset(10);
        make.left.equalTo(nurseTitlLb.mas_right);
        make.right.equalTo(_tagLb.mas_left).offset(-10);
    }];
   
    [_tagLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(nurseTitlLb.mas_centerY);
        make.right.equalTo(warp.mas_right).mas_offset(-15);
        make.left.equalTo(_nurseTitlLb.mas_right);
        make.width.mas_offset([_tagLb.text widthForFont:_tagLb.font] + 10);
        make.height.mas_offset([_tagLb.text heightForFont:_tagLb.font width:[_tagLb.text widthForFont:_tagLb.font]] + 5);
    }];
    
    UIView *bottomLine = [UIView new];
    bottomLine.backgroundColor = CSplitLineColor;
    [self.contentView addSubview:bottomLine];

    [bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_nurseTitlLb.mas_bottom).mas_offset(15);
        make.left.equalTo(warp).mas_offset(10);
        make.right.equalTo(warp).mas_offset(-10);
        make.height.offset(1);
    }];

    [_descLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bottomLine.mas_bottom).mas_offset(15);
        make.left.equalTo(warp).mas_offset(15);
        make.right.equalTo(warp).mas_offset(-15);
        make.bottom.equalTo(warp).mas_offset(-15);
    }];
}


- (void)configCellWithModel:(HEDocImMsgModel *)model {
    _docTitleLb.text = model.doctor_name;
    _nurseTitlLb.text = model.nurse_name;
    _timeLb.text = model.Kcreate_date;
    _descLb.text = model.Kmsg;
    _tagLb.text = model.KTag;
    _tagLb.backgroundColor = model.KTagColor;
    
    [self showbadge: !model.KIsRead];
}

- (void)showbadge:(BOOL)show {
  
    if (show) {
        [_timeLb pp_showBadge];
  
        _timeLb.badgeView.font = DYBlodFont(14);
        [_timeLb pp_addDotWithColor: CPriceColor];
        [_timeLb pp_setBadgeHeight: 12];
        [_timeLb pp_moveBadgeWithX: 5 Y: 0];
    }else {
        [_timeLb pp_hiddenBadge];
    }
}

@end

